# 匿名函数，类似java8的lambda表达式
add_function = lambda a, b: a + b

sum_result = add_function(1, 2)
print("sum_result", sum_result)

my_list = [1, 2, 3, 4, 5]
result = map(lambda x: x ** 2, my_list)  # 映射
print("map方法: ", list(result))

#  reduce  累积
from functools import reduce

result = reduce(lambda x, y: x * y, my_list)
print(result)

# filter 过滤
result = filter(lambda x: x % 2, my_list)
print(list(result))

my_list = [1, 2, 3, 40, 5, 6, 0, 6, 0, 5]  # 12340560605
result = filter(lambda x: x != 0, my_list)
print(list(result))

result = 0
mul = 1
for i in my_list[::-1]:
    result = result + i * mul
    mul = mul * 10 ** len(str(i))
print(result)

result = reduce(lambda x, y: x * 10 ** len(str(y)) + y, my_list)
print(result)
